package io.github.rascaler.dcenter.platforms.binance;

import com.binance.connector.futures.client.exceptions.BinanceClientException;
import com.binance.connector.futures.client.exceptions.BinanceConnectorException;
import com.binance.connector.futures.client.impl.UMFuturesClientImpl;
import com.binance.connector.futures.client.utils.ProxyAuth;
import io.github.rascaler.dcenter.constant.ConstantItem;
import io.github.rascaler.dcenter.db.DbManager;
import io.github.rascaler.dcenter.manager.BinanceManager;
import io.github.rascaler.dcenter.platforms.DbMapper;
import io.github.rascaler.dcenter.platforms.Parser;
import io.github.rascaler.dcenter.pojo.Candlestick;
import io.github.rascaler.dcenter.pojo.FixedArrayList;
import io.github.rascaler.dcenter.pojo.Instrument;
import io.github.rascaler.dcenter.properties.BinanceProperties;
import io.github.rascaler.dcenter.properties.ProxyInfo;
import io.github.rascaler.dcenter.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

/**
 * @ClassName BinanceStarter
 * @Description TODO
 * @Author wurenqing
 * @Date 2023-12-08 11:37
 */
@Slf4j
@Component
public class BinanceStarter implements CommandLineRunner {

    @Autowired
    private BinanceManager binanceManager;

    @Autowired
    private DbManager dbManager;

    @Override
    public void run(String... args) throws Exception {
        // 检查db，判断是否需要重新载入数据
        dbManager.getMdb().init();
        int count = 1;
        while (dbManager.getState() == 0) {
            log.info("binance第{}次尝试初始化db", count++);
            try {
                binanceManager.init();
                log.info("db数据初始化完成");
            }catch (Exception e) {
                dbManager.setState(0);
                log.error("db数据初始化失败", e);
            }finally {
                try {
                    Thread.sleep(60000);
                }finally {

                }
            }

        }

    }

}
